package com.weixin.paleituo.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.weixin.paleituo.R;
import com.weixin.paleituo.adapter.GoodsListPreRecycleAdapter;
import com.weixin.paleituo.adapter.TemplateGoodsRecycleAdapter;
import com.weixin.paleituo.base.BaseFragment;
import com.weixin.paleituo.bean.OrderGoods;
import com.weixin.paleituo.bean.TemplateDetailsBean;
import com.weixin.paleituo.bean.TemplateGoods;
import com.weixin.paleituo.contans.Contans;
import com.weixin.paleituo.util.UIUtils;
import com.weixin.paleituo.view.LoadingPagerHead;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 样板间详情，商品详情列表
 *
 * @author fengzhen
 * @version v1.0, 2018/4/20
 */
public class TemplateGoodsFragment extends BaseFragment {

    @BindView(R.id.recycler_fragment_template_goods)
    RecyclerView mRecyclerFragmentTemplateGoods;

    private ArrayList<TemplateGoods> mGoodsList = new ArrayList<>();
    private TemplateDetailsBean mTemplate;
    private LoadingPagerHead mLoadingPagerHead;

    public static TemplateGoodsFragment newInstance(TemplateDetailsBean template) {
        Bundle args = new Bundle();
        args.putSerializable(Contans.INTENT_DATA, template);
        TemplateGoodsFragment fragment = new TemplateGoodsFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View initView(Context context) {
        mLoadingPagerHead = new LoadingPagerHead(getContext()) {
            @Override
            protected void close() {
            }

            @Override
            protected View createSuccessView() {
                return UIUtils.inflate(getContext(), R.layout.fragment_template_goods);
            }

            @Override
            protected void reLoading() {
            }
        };
        return mLoadingPagerHead;
    }

    @Override
    protected void initData() {
        super.initData();

        mTemplate = (TemplateDetailsBean) getArguments().getSerializable(Contans.INTENT_DATA);

        List<TemplateGoods> goodsList = mTemplate.getGoodsList();
        if (goodsList == null || goodsList.size() <= 0) {
            mLoadingPagerHead.showPagerView(Contans.STATE_EMPTY);
        } else {
            mLoadingPagerHead.showPagerView(Contans.STATE_SUCCEED);
        }
        mGoodsList.addAll(goodsList);

        mRecyclerFragmentTemplateGoods.setLayoutManager(
                new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
        mRecyclerFragmentTemplateGoods.setAdapter(new TemplateGoodsRecycleAdapter(getContext(), mGoodsList));
    }
}
